package st.business.tepth.business.user.busnumber.workholder.repair.work.content;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;

import java.util.List;

import st.business.tepth.R;
import st.business.tepth.base.OnItemChooseListener;
import st.business.tepth.business.bean.DiagnoseBean;
import st.business.tepth.business.user.busnumber.workholder.adapter.TroubleCommonAdapter;

/**
 * @author zhangyu
 * @date 2019/8/2
 */
public class DiagnoseUiDelegate {
    private TextView mTvSearch;
    private TextView mTvCommonDiagnose;
    private RecyclerView mRecyclerViewCommonDiagnose;
    private TroubleCommonAdapter mCommonAdapter;
    private OnItemChooseListener<DiagnoseBean> mAddDiagnoseListener;

    public DiagnoseUiDelegate(Context context,
                              TextView tvSearch, TextView tvCommonDiagnose,
                              RecyclerView recyclerViewCommonDiagnose,
                              OnItemChooseListener<DiagnoseBean> addDiagnoseListener) {
        mTvSearch = tvSearch;
        mTvCommonDiagnose = tvCommonDiagnose;
        mRecyclerViewCommonDiagnose = recyclerViewCommonDiagnose;
        mAddDiagnoseListener = addDiagnoseListener;
        mRecyclerViewCommonDiagnose.setLayoutManager(new LinearLayoutManager(context,
                LinearLayoutManager.HORIZONTAL, false));
        mRecyclerViewCommonDiagnose.setAdapter(mCommonAdapter =
                new TroubleCommonAdapter(R.layout.item_trouble_common, null));
        mRecyclerViewCommonDiagnose.addOnItemTouchListener(new OnItemClickListener() {
            @Override
            public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
                DiagnoseBean diagnoseBean = (DiagnoseBean) adapter.getItem(position);
                if (diagnoseBean != null) {
//                    diagnoseBean.setRepair_id(mRepairId);
                    diagnoseBean.setReference_id(diagnoseBean.getId());
//                    diagnoseBean.setRepair_task_id(mRepairTaskId);
//                    diagnoseBean.setRepair_phenomenon_id(
//                            mTroublePagerAdapter.getTrouble(mCurrentTroubleIndex).getId());
                    diagnoseBean.setTemp(true);
                    diagnoseBean.setManual(false);
                    if (mAddDiagnoseListener != null) {
                        mAddDiagnoseListener.onChoose(diagnoseBean);
                    }
                }
            }
        });
        mTvSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }

    public void setData(List<DiagnoseBean> list) {
        mCommonAdapter.setNewData(list);
    }

    public void changeUiState(int status) {
        if (status < 3) {
            mTvSearch.setVisibility(View.VISIBLE);
            mTvCommonDiagnose.setVisibility(View.VISIBLE);
            mRecyclerViewCommonDiagnose.setVisibility(View.VISIBLE);
        } else {
            mTvSearch.setVisibility(View.GONE);
            mTvCommonDiagnose.setVisibility(View.GONE);
            mRecyclerViewCommonDiagnose.setVisibility(View.GONE);
        }
    }

}
